﻿using System;
using System.Collections.Generic;

namespace SpiderCore
{
    /// <summary>
    /// 页面数据仓库
    /// </summary>
    public static class PageRepository
    {
        private static object _syncObj = new object();
        private static Queue<PageData> _queue = new Queue<PageData>();
        /// <summary>
        /// 队列长度
        /// </summary>
        public static int Length
        {
            get { return _queue.Count; }
        }
        /// <summary>
        /// 将页面添加到队列
        /// </summary>
        /// <param name="pagedata"></param>
        public static void AddPage(PageData pagedata)
        {
            lock (_syncObj)
            {
                _queue.Enqueue(pagedata);
            }
        }
        /// <summary>
        /// 从队列中取出一个页
        /// </summary>
        /// <returns></returns>
        public static PageData GetPage()
        {
            if (_queue.Count != 0)
            {
                try
                {
                    return _queue.Dequeue();
                }
                catch (Exception)
                {
                    return null;
                }
            }
            return null;
           
        }
    }
}
